<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>设置库存信息setInventoryMessage</title>
	</head>
	<link rel="stylesheet" href="../css/common.css" />
	<style>
		
		table {						
			border-collapse:collapse;	
			margin:30px auto;	
		}
		th{
			font-weight:normal;
			padding:0 16px;
			background:#f0eeef;
		}
		td{
			padding:0 16px;
			text-align:center;
			background:#fafafa;
		}
		table td,th{
			height:32px;
			border:1px solid #e7e9e8;
			
		}
		tr td:first-child{
			color:#01a998;
		}
		input{
			border:none;
			width:40px;
			height:32px;
			background:#fafafa;
			outline:none;
			text-align:center;
			font-family:"微软雅黑"
		}
		.btn{
			text-align:center;
		}
		.btn button{
			width:116px;
			height:30px;
			border:none;
			font-family:"微软雅黑";
			color:white;
			outline:none;
			cursor:pointer;			
		}
		.btn1{
			background:#01a998;
		}
		.btn2{
			background:#a1a4a9;
		}
	</style>
	<body>
		<table>
			<thead>
			<tr>
				<th>舱位</th>
				<th>物理数</th>
				<th>最大数</th>
				<th>开放数</th>
				<th>切位限制数</th>
				<th>散客限制数</th>
				<th>切位已售</th>
				<th>散客已售</th>
				<th>总已售</th>
				<th>未售数</th>
				<th>物理可售</th>					
			</tr>
			</thead>
			<tbody>
			
			</tbody>
			
		</table>
		<div class='btn'><button class='btn1'>确认</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class='btn2'>取消</button></div>
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>
		<script type="text/javascript" src="../layer-v2.4/layer/layer.js" ></script>
		<script>
			
			 var url = document.location.href.toString();
			 var u = url.split("=");
			 //alert(u[1]);//通过URL向下一个页面传输的id数据
			 
			 $.ajax({
					type:"get",
					url:"../inventory/leg/"+u[1]+"/cabinList?temp="+Math.random(),
					async:true,
					dataType:"json",
					success:function(data){
						var tabHtml="";
						for(var i=0;i<data.data.length;i++){
							tabHtml+='<tr>'+
										'<td class="blue_size arrdata0">'+data.data[i].cabinName+'</td>'+
										'<td class="arrdata1">'+data.data[i].capacity+'</td>'+
										'<td class="arrdata2"><input type="text" class="max" value='+data.data[i].maxCapacity+'></td>'+
										'<td class="arrdata3"><input type="text" class="open" value='+data.data[i].openCapacity+'></td>'+
										'<td><input type="text" class="arrdata16" value='+data.data[i].groupCapacity+'></td>'+
										'<td><input type="text" class="arrdata15" value='+data.data[i].individualCapacity+'></td>'+
										'<td class="arrdata4">'+data.data[i].groupBooked+'</td>'+
										'<td class="arrdata5">'+data.data[i].individualBooked+'</td>'+
										'<td class="arrdata6">'+data.data[i].bookedSeat+'</td>'+
										'<td class="arrdata7">'+data.data[i].unsaldSeat+'</td>'+
										'<td class="arrdata17">'+data.data[i].unsaldCapacity+'</td>'+
										'<td class="arrdata8" style="display:none;">'+data.data[i].blockSeat+'</td>'+
										'<td class="arrdata9" style="display:none;">'+data.data[i].cabin+'</td>'+
										'<td class="arrdata10" style="display:none;">'+data.data[i].fltLegId+'</td>'+
										'<td class="arrdata11" style="display:none;">'+data.data[i].groupCapacity+'</td>'+
										'<td class="arrdata12" style="display:none;">'+data.data[i].id+'</td>'+
										'<td class="arrdata13" style="display:none;">'+data.data[i].individualCapacity+'</td>'+
										'<td class="arrdata14" style="display:none;">'+data.data[i].status+'</td>'+
									
									'</tr>';
									
						}
						$("table>tbody").append(tabHtml);
						
						//data_=data;
					}
					
				});	
    	
			 $(".btn1").click(function(){
				 //可以获取上个接口的数据
				 var len=$("table>tbody>tr").length;//获取表格行数
				 var dataArr = [];	//定义数组list用于装每条数据			 
				 for(var i=0;i<len;i++){
					 var json = {};
					 json.cabinName = $(".arrdata0").eq(i).text();
					 json.capacity = $(".arrdata1").eq(i).text();
					 json.maxCapacity = $(".max").eq(i).val()
					 json.openCapacity = $(".open").eq(i).val()
					 json.groupBooked = $(".arrdata4").eq(i).text()
					 json.individualBooked = $(".arrdata5").eq(i).text()
					 json.bookedSeat = $(".arrdata6").eq(i).text()
					 json.unsaldSeat = $(".arrdata7").eq(i).text()
					 //以下为隐藏掉的需要向后台传输的数据字段
					 json.blockSeat = $(".arrdata8").eq(i).text()
					 json.cabin = $(".arrdata9").eq(i).text()
					 json.fltLegId = $(".arrdata10").eq(i).text()
					 json.groupCapacity = $(".arrdata11").eq(i).text()
					 json.id = $(".arrdata12").eq(i).text()
					 json.individualCapacity = $(".arrdata13").eq(i).text()
					 json.status = $(".arrdata14").eq(i).text()
					 json.individualCapacity = $(".arrdata15").eq(i).val()
					 json.groupCapacity = $(".arrdata16").eq(i).val()
					 json.unsaldCapacity=$(".arrdata17").eq(i).text();//物理可售数
					 dataArr.push(json)
				 }
				 //console.log(dataArr);
				 //将得到的数据list传输给后台
				 $.ajax({
						type:"post",
						url:"../inventory/leg/updateCabinList?temp="+Math.random(),
						contentType:'application/json;charset=utf-8',
						data:JSON.stringify(dataArr),
						async:true,
						success:function(data){
							var data=JSON.parse(data);
							//alert(data.message);
							//layer.msg(data.message);
							if(data.status.toString()=="1001"){
								layer.msg(data.message, {icon: 1,time:1000},function(){
									var index = parent.layer.getFrameIndex(window.name);//获取弹窗索引
									parent.layer.close(index);//关闭弹窗
								});			
							}else{
								layer.msg(data.message, {icon: 2,time:1000})
							}
						}
					});
				  
				  
				
			 });
			 //取消执行关闭窗口
    		$(".btn2").click(function(){
    			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
   				 parent.layer.close(index);
    		});
			 
		</script>
	</body>
</html>
